package com.qf.device.controller;

import com.qf.device.entity.DeviceType;
import com.qf.device.service.DeviceTypeService;
import com.qf.dto.PageDto;
import com.qf.industy.entity.Industry;
import com.qf.industy.service.IndustryService;
import com.qf.vo.PageResult;
import com.qf.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 设备类型表 前端控制器
 * </p>
 *
 * @author zhu
 * @since 2023-10-26
 */
@RestController
@RequestMapping("/deviceType")
@CrossOrigin
public class DeviceTypeController {

    @Autowired
    private DeviceTypeService deviceTypeService;

    @Autowired
    private IndustryService industryService;

    /*分页查询*/
    @PostMapping("page")
    public PageResult<DeviceType> page(@RequestBody PageDto<DeviceType> pageDto){
        return deviceTypeService.pageInfo(pageDto);
    }

    /*设备行业查询*/
    @GetMapping("industry")
    public List<Industry> industry(){
        return industryService.list();
    }

    /*设备类型查询*/
    @GetMapping("type")
    public List<DeviceType> type(){
        return deviceTypeService.list();
    }

    /*设备增加和修改*/
    @PostMapping("add")
    public Result add(@RequestBody DeviceType deviceType){
        if (StringUtils.isEmpty(deviceType.getId())){
            return deviceTypeService.add(deviceType);
        }else{
            if(deviceTypeService.updateById(deviceType)){
                return new Result(0,"更新成功！");
            }else{
                return new Result(1,"更新失败！");
            }
        }
    }



}
